package com.neusoft.yuejian_01.activity;


import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.base.BaseActivity;
import com.neusoft.yuejian_01.javabean.UserBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.model.Const;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.model.UserModel;

import it.sephiroth.android.library.picasso.Picasso;

public class UpdateInfoActivity extends BaseActivity implements RetrofitListener{
    private EditText UserName,PassWord,UserPhone,UserEmail,UserAddress;
    private TextView  Baocun;
    private ImageView uu_Pic,Back;
    private Context context;

     protected void initView() {
         setContentView( R.layout.activity_updatelnfo);
        UserName = (EditText) findViewById(R.id.uName);
        PassWord= (EditText) findViewById(R.id.uPass);
        UserPhone= (EditText) findViewById(R.id.tel);
        UserEmail= (EditText) findViewById(R.id.email);
        UserAddress= (EditText) findViewById(R.id.address);
        Baocun= (TextView) findViewById(R.id.conserve);
        uu_Pic=(ImageView) findViewById(R.id.headpic);
        Back=(ImageView) findViewById(R.id.uback);
         setInfoListener();
    }

    @Override
    protected void initEvents() {

    }

    @Override
    protected void initData() {

    }

    private  void  setInfoListener(){
        UserModel userModel=new UserModel();
        userModel.userInfo(getUser_id(),this);

        //保存对我的信息的修改
        Baocun.setOnClickListener(new View.OnClickListener() {
            @Override
               public void onClick(View view) {
                String username = UserName.getText().toString();
                String userpass = PassWord.getText().toString();
                String mobilenum = UserPhone.getText().toString();
                String address = UserAddress.getText().toString();
                String email = UserEmail.getText().toString();
                UserModel userModel=new UserModel();
                userModel.updateInfo(getUser_id(),username,userpass,mobilenum,address,email,UpdateInfoActivity.this);
            }
   });

//返回到我
        Back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
    @Override
    public void onSuccess(Object object, int flag) {
        switch (flag){
            case Const.UserInfo:
                UserBean userInfo = (UserBean)object;
                UserName.setText(userInfo.getU_name());
                PassWord.setText(userInfo.getU_pass());
                UserPhone.setText(userInfo.getU_phone());
                UserEmail.setText(userInfo.getU_email());
                UserAddress.setText(userInfo.getU_address());
                String  headpic= ConstPhoto.BASE_URL+ConstPhoto.SetPictureFile+userInfo.getU_pic();
                Picasso.with(context).load( headpic).into(uu_Pic);
                break;
            case Const.UpdateInfo:
                UserBean userBean=(UserBean)object;
                if (userBean.getSuccess().equals("0")) {

                    Toast.makeText(UpdateInfoActivity.this, "修改失败", Toast.LENGTH_SHORT).show();

                } else {
                    Toast.makeText(UpdateInfoActivity.this, "修改成功", Toast.LENGTH_SHORT).show();

                }
                break;
        }

    }
    @Override
    public void onFail() {

    }
}
